/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.scene.controller;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.scene.bean.ItemListBean;
import com.koron.scene.service.api.GoodsListService;
import com.koron.scene.utils.BusinessCode;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 物品列表
 */
@Api(tags = "goodsList", description = "物品列表")
@RestController
@RequestMapping("/goodsList")
public class GoodsListController {
    @Autowired
    private GoodsListService goodsListService;

    @ApiOperation("列表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "水司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemName", value = "物品名称" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemType", value = "物品种类code" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemSpecification", value = "物品规格" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "page", value = "当前页" , dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数" , dataType = "Integer", paramType = "query")
    })
    @GetMapping(value = "/queryForList.htm")
    public MessageBean queryForList(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore String corpCode, @ApiIgnore String itemName,
                                    @ApiIgnore String itemType, @ApiIgnore String itemSpecification,
                                    @ApiIgnore Integer page, @ApiIgnore Integer pageSize) {
        if (user == null) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return goodsListService.queryForList(corpCode, itemName, itemType, itemSpecification, page, pageSize);
    }

    @ApiOperation("单条记录查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")
    })
    @GetMapping(value = "/queryById.htm")
    public MessageBean queryById(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore String id) {
        if (user == null) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return goodsListService.queryById(id);
    }

    @ApiOperation("删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")
    })
    @PostMapping(value = "/queryById.htm")
    @Log(title = "物品列表删除", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean deleteById(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore String id) {
        if (user == null) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return goodsListService.deleteById(id);
    }

    @ApiOperation("新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "水司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpName", value = "水司名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemName", value = "物品名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemType", value = "物品种类", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemTypeName", value = "物品种类名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemSpecification", value = "物品规格", required = true, paramType = "query", dataType = "String"),
    })
    @PostMapping("/insert.htm")
    @Log(title = "物品列表新增", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean insert(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                              @ApiIgnore ItemListBean bean) {
        if (user == null) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return goodsListService.insert(user, bean);
    }

    @ApiOperation("修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemName", value = "物品名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemType", value = "物品种类", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemTypeName", value = "物品种类名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "itemSpecification", value = "物品规格", required = true, paramType = "query", dataType = "String"),
    })
    @PostMapping("/update.htm")
    @Log(title = "物品列表修改", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean update(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                              @ApiIgnore ItemListBean bean) {
        if (user == null) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return goodsListService.update(user, bean);
    }
}
